#include "opencv2/opencv.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    Mat in_image, out_image;

    // Usage: <cmd> <file_in> <file_out>
    // Read original image

    in_image = imread(argv[1], IMREAD_UNCHANGED);
    if (in_image.empty()) {
        // Check whether the image is read or not
        cout << "Error! Input image cannot be read ...\n";
        return -1;
    }

    // Creates two windows with the names of the images
    namedWindow(argv[1], WINDOW_AUTOSIZE);
    namedWindow(argv[2], WINDOW_AUTOSIZE);
    // Shows the image into the previously created window
    imshow(argv[1], in_image);
    cvtColor(in_image, out_image, COLOR_BGR2GRAY);
    imshow(argv[2], out_image);

    cout << "Press any key to exit ...\n";
    waitKey();

    // Writing image
    imwrite(argv[2], out_image);

    return 0;
}

